﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;


namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeInsertFranchiseDataAction : BestLifeDataAction<int>
    {

        private Franchise GvFrn;
        public BestLifeInsertFranchiseDataAction(Franchise PFrn)
        {
            GvFrn = PFrn;
        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertFranchise";



                
                LvCommand.Parameters.Add(new SqlParameter("@Frn_ID", GvFrn.F_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Dis_ID", GvFrn.Dis_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Shop_Name", GvFrn.Shop_Name.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Location", GvFrn.Location.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Desc", GvFrn.Description.ToString()));

                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvFrn.User_Create.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create", DateTime.Parse(GvFrn.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", DateTime.Parse(GvFrn.Last_Modify.ToString())));




                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 

            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
